<?php

include("global.php");

$pagetitle=" - Administration - Config";
$links=" > Administration > Config";

include ("header.php");

include ("admin_header.php");

if($userloggedinarray[15]!=="administrator"){
   $tplcontent['notice']="Must be logged in as administrator to use control panel!";
   echo template('notice',$tplcontent);
}else{

 if(!$editconfig){

 unset($tplcontent);
 $tplcontent['formheader'].="<form action=\"admin_config.php\" method=post>";
 $tplcontent['formheader'].="<input type=hidden name=\"editconfig\" value=\"1\" size=40>"; 
 
 $tplcontent['boardtitle'].="<input type=text name=\"boardtitle\" value=\"$configarray[0]\" size=40 class=\"forminput\">";
 $tplcontent['adminemail'].="<input type=text name=\"adminemail\" value=\"$configarray[35]\" size=40 class=\"forminput\">";
 $tplcontent['mainwebsite'].="<input type=text name=\"mainwebsite\" value=\"$configarray[36]\" size=40 class=\"forminput\">";
 
 $languagearray=listdirs("languages");
 $tplcontent['language'].="<select size=1 name=\"defaultlanguage\" size=40 class=\"forminput\">\n";
 for($n=0;$n<count($languagearray);$n++){

  if($languagearray[$n]==$configarray[48]){
  $tplcontent['language'].="<option value=\"$languagearray[$n]\" selected>$languagearray[$n]</option>";
  }else{
  $tplcontent['language'].="<option value=\"$languagearray[$n]\">$languagearray[$n]</option>";
  }

 }
 $tplcontent['language'].="</select>";

 if($configarray[34]=="on")
 {
 	$tplcontent['texttitle'].="<input type=checkbox name=\"textlogo\" class=\"forminput\" checked>";
 }else{
 	$tplcontent['texttitle'].="<input type=checkbox name=\"textlogo\" class=\"forminput\">";
 }
 
 
 $tplcontent['maxlevelssubforums'].="<input type=text name=\"maxsubforumdisplay\" value=\"$configarray[27]\" size=2 class=\"forminput\">";
 if($configarray[42]=="on"){
 	$tplcontent['countreplyduringpost'].="<input type=checkbox name=\"dontscanreplycount\" class=\"forminput\" checked>";
 }else{
 	$tplcontent['countreplyduringpost'].="<input type=checkbox name=\"dontscanreplycount\" class=\"forminput\">";
 }

 $tplcontent['forumindent'].="<input type=text name=\"indentspacing\" value=\"$configarray[44]\" size=2 class=\"forminput\">%";
 
 $tplcontent['postfloodcontrol'].="<input type=text name=\"postfloodcontrolsec\" value=\"$configarray[37]\" size=2 class=\"forminput\">";
 $tplcontent['nestedbbcodes'].="<input type=text name=\"nestedbbcodes\" value=\"$configarray[43]\" size=2 class=\"forminput\">";
 $tplcontent['smiliesperline'].="<input type=text name=\"smiliesperline\" value=\"$configarray[47]\" size=2 class=\"forminput\">";
 
 $tplcontent['maxsmilies'].="<input type=text name=\"maxsmilies\" value=\"$configarray[3]\" size=2 class=\"forminput\"><br>";
 $tplcontent['maxbbcode'].="<input type=text name=\"maxbbcode\" value=\"$configarray[4]\" size=2 class=\"forminput\"><br>";
 
 if($configarray[45]=="on"){
 	$tplcontent['nameuserlevels'].="<input type=checkbox name=\"userlevelnames\" class=\"forminput\" checked>";
 }else{
 	$tplcontent['nameuserlevels'].="<input type=checkbox name=\"userlevelnames\" class=\"forminput\">";
 }

 if($configarray[46]=="on"){
 	$tplcontent['showalledits'].="<input type=checkbox name=\"showalledits\" class=\"forminput\" checked>";
 }else{
 	$tplcontent['showalledits'].="<input type=checkbox name=\"showalledits\" class=\"forminput\">";
 }
 

 $tplcontent['regfloodcontrol'].="<input type=text name=\"regfloodcontrolsec\" value=\"$configarray[38]\" size=2 class=\"forminput\">";

 if($configarray[39]=="on"||$configarray[39]==""){
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"on\" class=\"forminput\" checked> ";
 }else{
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"on\" class=\"forminput\"> ";
 }
 $tplcontent['regmethod'].="Allowed<br>";
 if($configarray[39]=="confirm"){
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"confirm\" class=\"forminput\" checked> ";
 }else{
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"confirm\" class=\"forminput\"> ";
 }
 $tplcontent['regmethod'].="Email confirmed<br>";
 if($configarray[39]=="approve"){
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"approve\" class=\"forminput\" checked> ";
 }else{
 $tplcontent['regmethod'].="<input type=radio name=\"registration\" value=\"approve\" class=\"forminput\"> ";
 }
 $tplcontent['regmethod'].="Admin approved";

 if($configarray[32]=="on"){
 $tplcontent['allowduplicatedisplay'].="<input type=checkbox name=\"allowdupdisplay\" class=\"forminput\" checked>";
 }else{
 $tplcontent['allowduplicatedisplay'].="<input type=checkbox name=\"allowdupdisplay\" class=\"forminput\">";
 }

 if($configarray[41]=="off"){
 	$tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"off\" class=\"forminput\" checked> ";
 }else{
 	$tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"off\" class=\"forminput\"> ";
 }
 $tplcontent['displaynamechange'].="Not allowed<br>";
 if($configarray[41]=="on"||$configarray[41]==""){
 	$tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"on\" class=\"forminput\" checked> ";
 }else{
 	$tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"on\" class=\"forminput\"> ";
 }
 $tplcontent['displaynamechange'].="Allowed<br>";
 if($configarray[41]=="approve"){
	 $tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"approve\" class=\"forminput\" checked> ";
 }else{
	 $tplcontent['displaynamechange'].="<input type=radio name=\"displaychange\" value=\"approve\" class=\"forminput\"> ";
 }
 $tplcontent['displaynamechange'].="Admin approved";
 
 $tplcontent['dateformat'].="<input type=text name=\"defaulttime\" value=\"$configarray[33]\" size=40 class=\"forminput\">";

 $tplcontent['maxbuddylist'].="<input type=text name=\"buddylistmax\" value=\"$configarray[28]\" size=2 class=\"forminput\">";

 $tplcontent['avatarsizelimit'].="<input type=text name=\"avatarfilesize\" value=\"$configarray[9]\" size=20 class=\"forminput\"><br>";

 $tplcontent['avatardimensionlimit'].="<input type=text name=\"avatardimension\" value=\"$configarray[10]\" size=20 class=\"forminput\"><br>";

 $tplcontent['attachmentextensions'].="<input type=text name=\"allowedattachext\" value=\"$configarray[22]\" size=50 class=\"forminput\">";

 $tplcontent['maxattachmentsize'].="<input type=text name=\"maxattachsize\" value=\"$configarray[23]\" size=20 class=\"forminput\">";

 $tplcontent['maxtotalattachmentsize'].="<input type=text name=\"maxtotalattachsize\" value=\"$configarray[31]\" size=20 class=\"forminput\">";

 $tplcontent['maxpolloptions'].="<input type=text name=\"maxpolloptions\" value=\"$configarray[24]\" size=2 class=\"forminput\">";

 $themesarray=listdirs("themes");
 $tplcontent['defaulttheme'].="<select size=1 name=\"defaulttheme\" size=40 class=\"forminput\">\n";
 for($n=0;$n<count($themesarray);$n++){

  if($themesarray[$n]==$configarray[12]){
  	$tplcontent['defaulttheme'].="<option value=\"$themesarray[$n]\" selected>$themesarray[$n]</option>";
  }else{
  	$tplcontent['defaulttheme'].="<option value=\"$themesarray[$n]\">$themesarray[$n]</option>";
  }

 }
 $tplcontent['defaulttheme'].="</select>";

 $tplcontent['inactivityseconds'].="<input type=text name=\"inactivityseconds\" value=\"$configarray[13]\" size=2 class=\"forminput\">";

 $tplcontent['topicsperpage'].="<input type=text name=\"topicsperpage\" value=\"$configarray[7]\" size=2 class=\"forminput\"><br>";

 $tplcontent['postsperpage'].="<input type=text name=\"postperpage\" value=\"$configarray[8]\" size=2 class=\"forminput\"><br>";

 $tplcontent['maxcharspostbody'].="<input type=text name=\"maxcharsbody\" value=\"$configarray[18]\" size=5 class=\"forminput\"><br>";

 $tplcontent['maxcharspostsubject'].="<input type=text name=\"maxcharssubject\" value=\"$configarray[25]\" size=5 class=\"forminput\"><br>";

 $tplcontent['maxcharssignature'].="<input type=text name=\"maxcharssigs\" value=\"$configarray[19]\" size=5 class=\"forminput\"><br>";

 if($configarray[21]=="disablegz"){
 	$tplcontent['gzcompression'].="<input type=checkbox name=\"gzcompress\" class=\"forminput\">";
 }else{
 	$tplcontent['gzcompression'].="<input type=checkbox name=\"gzcompress\" class=\"forminput\" checked>";
 } 

 $tplcontent['maxtotalpmsize'].="<input type=text name=\"maxpmsize\" value=\"$configarray[29]\" size=10 class=\"forminput\">";

 $tplcontent['maxtotalpmnumber'].="<input type=text name=\"maxpmnumber\" value=\"$configarray[30]\" size=10 class=\"forminput\"><br>";

 $tplcontent['boardclosemessage'].="<input type=text name=\"boardclosing\" value=\"$configarray[40]\" size=60 class=\"forminput\"><br>";

 $tplcontent['submitbutton'].="<input type=submit name=\"submit\" value=\"Update\" class=\"formbutton\">";

 $tplcontent['formfooter'].="</form>";
 
 echo template('adminconfig',$tplcontent);
 }

 if($editconfig){

 $boardtitle=stripslashes($boardtitle);
 $boardtitle=htmlentities($boardtitle);
 writedata("$maindatadir/config.php",$boardtitle,0);
 writedata("$maindatadir/config.php",$maxsmilies,3);
 writedata("$maindatadir/config.php",$maxbbcode,4);
 writedata("$maindatadir/config.php",$topicsperpage,7);
 writedata("$maindatadir/config.php",$postperpage,8);
 writedata("$maindatadir/config.php",$avatarfilesize,9);
 writedata("$maindatadir/config.php",$avatardimension,10);
 writedata("$maindatadir/config.php",$defaulttheme,12);
 writedata("$maindatadir/config.php",$inactivityseconds,13);
 if($html=="on"){
 writedata("$maindatadir/config.php","allowhtml",14);
 }else{
 writedata("$maindatadir/config.php","denyhtml",14);
 }
 writedata("$maindatadir/config.php",$maxcharsbody,18);
 writedata("$maindatadir/config.php",$maxcharssigs,19);
 if($gzcompress=="on"){
 writedata("$maindatadir/config.php","enablegz",21);
 }else{
 writedata("$maindatadir/config.php","disablegz",21);
 }
 writedata("$maindatadir/config.php",$allowedattachext,22);
 writedata("$maindatadir/config.php",$maxattachsize,23);
 writedata("$maindatadir/config.php",$maxpolloptions,24);
 writedata("$maindatadir/config.php",$maxcharssubject,25);
 writedata("$maindatadir/config.php",$maxsubforumdisplay,27);
 writedata("$maindatadir/config.php",$buddylistmax,28);
 writedata("$maindatadir/config.php",$maxpmsize,29);
 writedata("$maindatadir/config.php",$maxpmnumber,30);
 writedata("$maindatadir/config.php",$maxtotalattachsize,31);
 writedata("$maindatadir/config.php",$allowdupdisplay,32);
 writedata("$maindatadir/config.php",$defaulttime,33);
 writedata("$maindatadir/config.php",$textlogo,34);
 writedata("$maindatadir/config.php",$adminemail,35);
 writedata("$maindatadir/config.php",$mainwebsite,36);
 writedata("$maindatadir/config.php",$postfloodcontrolsec,37);
 writedata("$maindatadir/config.php",$regfloodcontrolsec,38);
 writedata("$maindatadir/config.php",$registration,39);
 writedata("$maindatadir/config.php",$boardclosing,40);
 writedata("$maindatadir/config.php",$displaychange,41);
 
 if($configarray[42]!=="on"&&$dontscanreplycount=="on"){//if turning on for first time, make a recount
  for($n=0;$n<count($forumarray);$n++){
  $topicarray=listdirs("$configarray[2]/$forumarray[$n]");
  $replies=0;
   for($m=0;$m<count($topicarray);$m++){
    $postarray2=listfiles("$configarray[2]/$forumarray[$n]/$topicarray[$m]");
    $replies+=count($postarray2)-1;
   }
  writedata("$configarray[2]/$forumarray[$n].php",$replies,11);
  }
 writedata("$maindatadir/config.php",$dontscanreplycount,42);
 }else{
 writedata("$maindatadir/config.php",$dontscanreplycount,42);
 }
 
 writedata("$maindatadir/config.php",$nestedbbcodes,43);
 writedata("$maindatadir/config.php",$indentspacing,44);
 writedata("$maindatadir/config.php",$userlevelnames,45);
 writedata("$maindatadir/config.php",$showalledits,46);
 writedata("$maindatadir/config.php",$smiliesperline,47);
 writedata("$maindatadir/config.php",$defaultlanguage,48);
 
 echo template('noticeadminconfigupdated',$tplcontent);
 }

}

 include("admin_footer.php");

 include("footer.php");

?>
